// 属性管理API
import request from '@/utils/request'
import type { CategoryResData, Attr } from './type'
enum API {
  // 一级分类
  c1_url = '/admin/product/getCategory1',
  // 二级分类
  c2_url = '/admin/product/getCategory2/',
  // 三级分类
  c3_url = '/admin/product/getCategory3/',
  // 根据分类获取属性
  attr_url = '/admin/product/attrInfoList/',
  // 添加/修改已有属性
  add_update_url = '/admin/product/saveAttrInfo',
  delete_attr_url = '/admin/product/deleteAttr/',
}

// 获取一级分类接口
export const reqC1 = () => request.get<any, CategoryResData>(API.c1_url)
// 获取二级分类接口
export const reqC2 = (c1: number) =>
  request.get<any, CategoryResData>(API.c2_url + c1)
// 获取三级分类接口
export const reqC3 = (c2: number) =>
  request.get<any, CategoryResData>(API.c3_url + c2)
// 获取对应分类下的属性
export const reqAttr = (c1: number, c2: number, c3: number) =>
  request.get<any, any>(`${API.attr_url}${c1}/${c2}/${c3}`)
// 添加/修改属性
export const reqAddUpdateAttr = (data: Attr) =>
  request.post<any, any>(API.add_update_url, data)
// 删除属性
export const reqDeleteAttr = (attrid: number) =>
  request.delete<any, any>(API.delete_attr_url + attrid)
